Ext.onReady(function() {

	// Disable browser right click
	Ext.fly(document.body).on('contextmenu', function(e, target) {
		e.preventDefault();
	});	
			
	Ext.QuickTips.init();

	Ext.getUrlParam = function(param) {
		var params = Ext.urlDecode(location.search.substring(1));
		return param ? params[param] : params;	
	}; 

	var viewPort = new Ext.Viewport({
			layout: 'border'
		,	autoScroll: true
		,	items: [{
					height: 95
				,	cls: 'glossary-header'		
				,	region: 'north'
				,	xtype: 'box'
				,	border: false
				,	margins: '0 0 5 0'					
				,	html: '<div class="header">'+
					 '<a href="http://www.gbif.org/" target="_blank" class="gbif">'+
						 '<img src="resources/images/gbif.jpg" alt="GBif" width="104" height="90" border="0" /></a>'+
					 '<div class="header-text">'+
						 '<h1>GBIF Resources</h1>'+
						 '<p>Darwin Core &amp; Extensions Definitions</p>'+
					 '</div></div>'
			}, new Gbif.Glossary.Manager({
					region:'center'
				,	border:false
				,	listeners:{
						render:function(){
							if (Ext.isDefined( Ext.getUrlParam('term') ) ) {								
								var term = Ext.getUrlParam('term');
								term = term.replace(/\+/g, " ");
								var letter = Ext.util.Format.substr(term,0,1);
								var lettertext = Ext.util.Format.substr(term, 0, 1).toUpperCase();
								this.invokeTermsTab('letter', 'Term', lettertext,'iconText', term);
							}
							if (Ext.isDefined( Ext.getUrlParam('letter') ) ) {
								var letter = Ext.util.Format.substr(Ext.getUrlParam('letter'), 0, 1).toUpperCase();
								this.invokeTermsTab('letter', 'Letter', letter, 'iconText', '');
							}
							if (Ext.isDefined( Ext.getUrlParam('code') ) ) {
								var code = Ext.getUrlParam('code');
								this.invokeTermsTab('code', 'Code', code,'iconText');
							}
							if (Ext.isDefined( Ext.getUrlParam('codeStatus') ) ) {
								var codeStatus = Ext.getUrlParam('codeStatus');
								this.invokeTermsTab('codeStatus', 'Code Status', codeStatus,'iconText');
							}
							if (Ext.isDefined( Ext.getUrlParam('termType') ) ) {
								var termType = Ext.getUrlParam('termType');
								this.invokeTermsTab('termType', 'Term Type', termType,'iconText');
							}
							if (Ext.isDefined( Ext.getUrlParam('searchType') ) ) {
								var termType = Ext.getUrlParam('searchType');
								var highlight = Ext.getUrlParam('highlight');
								var query = Ext.getUrlParam('query').replace(/\+/g, " ");
//console.log(								this.tabpanel.welcomeTab.searchDefinition );
								this.tabpanel.welcomeTab.searchDefinition.setValue(query);
								this.tabpanel.welcomeTab.SearchStore.load({ 
									params: {
											searchType: 'fulltext'
										,	query: query
										,	highlight: highlight
									}
								});
							}
						}
					}
				})
			]
	});

	Ext.get('cover1').remove();
	Ext.get('cover2').remove();
	Ext.get('cover3').remove();
	Ext.get('cover4').remove();
	Ext.get('cover5').remove();
	Ext.get('loading').remove();
	Ext.get('loading-mask').fadeOut({remove:true});

});